﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lm.Common.Serialization
{
    public class BinaryFormatter
    {
        public byte[] Serialize(object obj)
        {
            using (var ms = new System.IO.MemoryStream())
            {
                new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Serialize(ms, obj);
                return ms.ToArray();
            }
        }

        public T Deserialize<T>(byte[] buf)
        {
            using (var ms = new System.IO.MemoryStream(buf))
            {
                return (T)new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Deserialize(ms);
            }
        }
    }
}
